<template>
	<view class="relative">
		<view class="padding-sm">
			<text v-for="(room,index) in rooms" @tap="checkRoom(room)" :key="index"
				class="padding-xs margin-xs bg-g-main text-main inline-block">{{room.rname}}</text>
		</view>
		<view class="padding" v-if="rooms.length < pageInfo.total">
			<button @click="loadMore" class="cu-btn block bg-main lg">显示更多</button>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			storeid: {
				default: "",
				type: String,
			}
		},
		data: function() {
			return {
				CustomBar: this.CustomBar,
				StatusBar: this.StatusBar,
				rooms: [],
				pageInfo: {
					current: 1,
					size: 16,
					total: 0
				},
				locamap: {},
				tp: {},
				func: {},
				searchObj: {
					rname: "",
					storeid: "",
					tp: "",
					func: "",
					cd: null,
					st: null,
					et: null
				}
				
			}
		},
		computed: {
			currentPosition: function() {
				if (this.store.state.position) {
					return this.store.state.position;
				}
				return undefined;
			}
		},
		created: function(){
			this.search();
		},
		methods: {
			checkRoom: function(fj) {
				this.$emit("change", fj);
			},
			search: function(param) {
				this.rooms = [];
				this.pageInfo.current = 1;
				this.loadRooms(param);
			},
			loadMore: function() {
				this.pageInfo.current++;
				this.loadRooms();
			},
			loadRooms: function(param) {
				
				if (param) {
					this.searchObj.storeid = param.storeid;
					this.searchObj.func = param.func;
					this.searchObj.tp = param.tp;
					this.searchObj.cd = param.cd;
					this.searchObj.st = param.st;
					this.searchObj.et = param.et;
				}
				
				this.searchObj.current = this.pageInfo.current;
				this.searchObj.size = this.pageInfo.size;
				this.searchObj.flg = true;
				
				if (this.currentPosition) {
					this.searchObj.jd = this.currentPosition.jd;
					this.searchObj.wd = this.currentPosition.wd;
				}
				
				this.api("/room/page").send(this.searchObj).then(data => {
					this.pageInfo.current = data.arooms.current;
					for (let index in data.arooms.records) {
						let record = data.arooms.records[index];
						record.sheng = this.location.localmap.cmap[record.pcode].criname;
						record.shi = this.location.localmap.cmap[record.scode].criname;
						record.qu = this.location.localmap.cmap[record.qcode].criname;
						record.tpname = this.tp[record.tp];
						record.funcname = this.func[record.func];
						if (record.distance) {
							record.distance = this.util.formatDistance(record.distance);
						}
						this.rooms.push(record);
					}
				});
				
			
			},
		}
	}
</script>

<style>
</style>